% update demo9, by initializing anchor centroids with litekmeans(X)
% 2022-10-11 save the running time in folder 12, change the transpose
% operation to from inside 'algo' to 'demo'. delete obj calculation. to
% spare time.
% 2022-9-- save the running time in folder 11, because in folder 10, the running
% time cost is higher owing to other programs.
clear;
clc;
warning off;

addpath(genpath('./'));

% dsPath = './';
% dsPath = '/media/maggie/Data/datasets/MultiviewDatasets_Features/';
dsPath = 'E:\datasets\MultiviewDatasets_Features\';
% dsPath = '/home/maggie/Desktop/lsy/datasets';
resPath = './res_obj_Folder_12/';


% dataNameset = { 'ALOI-100','AwA_fea','BBCSport','BDGP_fea','Caltech101-7','Caltech101-20','Caltech101-all_fea','CCV','Handwritten_numerals','Mfeat',...
%     'mnist_1','mnist_2','mnist_3','mnist_4','mnist_5','MNIST_fea','NUSWIDEOBJ','NUS-WIDE-OBJECT_fea','ORL_mtv','SUNRGBD_fea',...%'Reuters2',...
%     'Wiki_fea','YoutubeFace_sel_fea'};


% dataset with ascending order  
dataNameset = {
'Texas',...
'Cornell',...
'WebKB_Wisconsin2views',...
'Washington',...
'Wisconsin',...
'WikipediaArticles',...
'3sources',...
'WebKB',...
'BBCSport',...
'100Leaves',...%10
'MFeat_2Views',...
'proteinfold',...
'proteinFold',...
'BDGP',...
'MSRCV1',...                                                     
'CiteSeer',...
'CCV',...
'Handwritten_numerals',...
'Mfeat',...
'handwritten',...%20
'Reuters-1200',...
'HW_6Views',...
'prokaryotic',...
'uci-digit',...
'BDGP_fea',...
'Hdigit',...
'Caltech7-2view',...
'Yale',...
'ALOI-100',...
'NUS-WIDE-Lite',...%30
'NUS-WIDE-OBJECT-10',...
'Caltech101-7',...
'Reuters-7200',...
'ORL_3Views',...
'ORL_mtv',...
'Caltech101-20',...
'Caltech101-all_fea',...
'Caltech101',...
'NUS-WIDE-OBJECT',...
'AWA-10',...%40
'Flower17',...
'STL10_4Views',...
'SUNRGBD_fea',...
'YoutubeFace_sel_fea',...
'CIFAR10_All_6Views',...%can't run this反序列化期间内存不足
'FashionMNIST',...%反序列化期间内存不足
'CIFAR100_All_4Views',...%47
'CIFAR10_All_4Views'}; 


%% 

for idata = [15] %3,12,13,14,15,16,25,27,31,32,36,39,43,44
    dataName = dataNameset{idata}; disp(dataName);
    load(strcat(dsPath,dataName),'X','Y');
%     load([resPath,'All_',dataName,'.mat'],'resall'); %%%%%%%%%%%%%%%%%%%%%%% deep = 5:10
    k = length(unique(Y));
    numview = length(X);
    anchor = 1*k;   %[k 2*k 3*k]
    d = k;  % dimension of [the last anchor] representation
    
    dmin = size(X{1},2);   % dimension of the first view
    for i = 1:numview
        di = size(X{i},2);
        dmin = di.*(di < dmin) + dmin.*(di >= dmin);  % update dmin
    end
    
    for i = 1:numview
        X{i} = mapstd(X{i}',0,1); % turn into d*n
    end

%     for deep = 1:floor((dmin - d)/2) % suppose W being split into [deep] matrices
    for deep =  1:5   % deep = 1 means no factorization
        d_vec = zeros(deep,1);
        for id = 1:(deep-1)
            d_vec(id) = (deep - id) * floor((dmin - d)/deep) + d; % d_vec is counting down.
        end
        d_vec(deep) = d;
        
        tic;
        [U,A,W,Z,iter,alpha] = algoMVDSC_v10(X,Y,d_vec,anchor); % X,Y,lambda,d,numanchor. Here, W is the a cell of dimension: (numview*deep).
        res = myNMIACCwithmean(U,Y,k);
        timer{idata,deep} = toc;
        resall{idata,deep} = res;
%         objall{idata,deep} = obj;
        fprintf('Anchor:\t%d \t ACC:%12.6f \t NMI:%12.6f \t Purity:%12.6f \t Fscore:%12.6f \t Time:%12.6f \n',[anchor res(1) res(2) res(3) res(4) toc]);
        wazPath = strcat('./WAZ_Folder_12/',dataName,'/');
        if (~exist(wazPath,'file'))
            mkdir(wazPath);
            addpath(genpath(wazPath));
        end
        wazname = ['deep',num2str(deep),'.mat'];
        save([wazPath,wazname],'W','A','Z');
%         save([resPath,'All_',dataName,'.mat'],'resall','objall','timer');
        if (~exist(resPath,'file'))
            mkdir(resPath);
            addpath(genpath(resPath));
        end
        save([resPath,'All_',dataName,'.mat'],'resall','timer');
    end
    clear U W A Z X Y d_vec anchor;
end


